home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / music / 13 / utility / rtxdemo.c < prev    next >
Text File  |  1986-05-12  |  6KB  |  222 lines

  1. /************************************************************************/
  2. /*                                     */
  3. /*         RRRRRRRRR       TTTTTTTTTTTTTTT      XXX     XXX        */
  4. /*         RRR     RRR           TTT             XXX   XXX        */
  5. /*         RRR     RRR           TTT              XXX XXX         */
  6. /*         RRRRRRRRR             TTT                XXX            */
  7. /*         RRR    RRR            TTT              XXX XXX         */
  8. /*         RRR     RRR           TTT             XXX   XXX        */
  9. /*         RRR     RRR           TTT            XXX     XXX        */
  10. /*                                     */
  11. /*    MICRO RTX  -  Atari ST Multitasking Operating System Kernel    */
  12. /*                                     */
  13. /*    (c) Copyright 1986 by David Beckemeyer                */
  14. /*                                     */
  15. /*                                     */
  16. /*    This short demonstaration program demonstates some of the    */
  17. /*    multitasking capabilities of the Atari ST computer.        */
  18. /*                                     */
  19. /*    This is a sample of a MICRO RTX multitasking application.    */
  20. /*    As you can see, MICRO RTX applications can be as simple as you    */
  21. /*    want.  The standard GEMDOS functions operate as usual, with    */
  22. /*    automatic multitasking.                        */
  23. /*                                    */
  24. /*    This MICRO RTX application is a simple "shell" that shows    */
  25. /*    how to use the kernel to get automatic multitasking.        */
  26. /*                                    */
  27. /*    When run, the shell will prompt with a "*".  It accepts the    */
  28. /*    following one letter commands:                    */
  29. /*                                    */
  30. /*        e - execute a program file                */
  31. /*        h - create background CPU hog                */
  32. /*        l - list a file on the screen                */
  33. /*        m - spool a file to the modem (RS-232)            */
  34. /*        p - spool a file to the printer                */
  35. /*        s - show processes                    */
  36. /*        x - exit demo program                    */
  37. /*                                    */
  38. /*    The e, l, m, and p commands prompt for a file name.  In each    */
  39. /*    case the complete path of the file (including the extension)    */
  40. /*    must be given.                            */
  41. /*                                    */
  42. /*    The e command will attept to execute the given program file.    */
  43. /*    This must not be a GEM program with this demo because the    */
  44. /*    mouse and screen are not set up for GEM.              */
  45. /*                                    */
  46. /*    The l, m, and p commands cannot be used concurrently.        */
  47. /*    This is because the demo uses the Unix style standard I/O    */
  48. /*    library for opening the files (from GEMLIB) and since this    */
  49. /*    code from DRI is not reentrant, the sharing of the GEMLIB    */
  50. /*    code doesn't work. This could be fixed by either re-writing    */
  51. /*    the standard I/O routines, or by using the GEMDOS style        */
  52. /*    calls (from osbind.h) Fopen, Fread, etc.  We are working on    */
  53. /*    our improved version of the Unix standard I/O library.        */
  54. /*                                    */
  55. /*    Keep in mind that standard "fopen", "fclose" calls work        */
  56. /*    normally for progams that always used them.  The problem    */
  57. /*    only comes about when you are actually sharing the data        */
  58. /*    & code segments, like this demo does.  The sub-processes    */
  59. /*    created here all share one copy of code from "GEMLIB" made    */
  60. /*    at link time.  When individual programs are run as a        */
  61. /*    single process, they each have their own copy of GEMLIB        */
  62. /*    so everything works fine.  Got it?                */
  63. /*                                    */
  64. /*    The h command just soaks up CPU time to demonstrate the        */
  65. /*    fantastic CPU horsepower of the ST.                */
  66. /*                                    */
  67. /*    With this MICRO RTX demo, you can run up to three background    */
  68. /*    processes.  This is a configuration limitation only.  You    */
  69. /*    can configure MICRO RTX for however many processes you want.    */
  70. /*                                    */
  71. /************************************************************************/
  72.  
  73. #include <stdio.h>
  74. #include <osbind.h>
  75.  
  76. char filename[64];
  77.  
  78. main()
  79. {
  80.     char buf[80];
  81.     char *p;
  82.     int i, delta;
  83.     char c;
  84.     int modem(), hog(), print();
  85.  
  86.     rtx_install();
  87.      delta = p_priority(0L, 0) - 100;
  88.      p_priority(0L, -delta);
  89.     printf("MICRO RTX - Atari ST Multitasking Operating System Kernel\n");
  90.     printf("(c) Copyright 1986 - David Beckemeyer\n\n");
  91.     printf("This program is Free!  It is a simple application program\n");
  92.     printf("that uses the MICRO RTX multitasking kernel to demonstrate\n");
  93.     printf("a few of the multitasking capabilities of the ST.\n\n");
  94.     printf("It may be freely distributed, provided all the introductory\n");
  95.     printf("messages remain intact.   MICRO RTX is available from:\n\n");
  96.     printf("\tBeckemeyer Development Tools\n");
  97.     printf("\t592 Jean Street #304\n");
  98.     printf("\tOakland, CA 94610\n");
  99.     printf("\t(415) 658-5318\n\n");
  100.  
  101.     do {
  102.         getline(buf, "* ");
  103.         switch (buf[0]) {
  104.         case 'e':
  105.             getline(buf, "Exec file: ");
  106.             Pexec(0, buf, "", "");
  107.             break;
  108.         case 'm':
  109.             getline(filename, "File: ");
  110.             p_create(100, 20, modem, 0, 0L);
  111.             break;
  112.         case 'h':
  113.             p_create(100, 20, hog, 0, 0L);
  114.             break;
  115.         case 'p':
  116.             getline(filename, "File: ");
  117.             p_create(100, 20, print, 0, 0L);
  118.             break;
  119.         case 's':
  120.             printf("Processes:\n----------\n\n");
  121.             showpall();
  122.             break;
  123.         case 'l':
  124.             getline(buf, "File: ");
  125.             list(buf);
  126.             break;
  127.         case '\0':
  128.         case 'x':
  129.             break;
  130.         case '?':
  131.             printf("e - exec a program (foreground)\n");
  132.             printf("h - create background CPU hog\n");
  133.             printf("l - dump file to screen (foreground)\n");
  134.             printf("m - spool file to RS-232\n");
  135.             printf("p - spool file to printer\n");
  136.             printf("s - show processes\n");
  137.             printf("x - exit\n");
  138.             break;
  139.         default:
  140.             printf("Unknown command - ? lists commands\n");
  141.             break;
  142.         }
  143.     } while (buf[0] != 'x');
  144.     rtx_remove();
  145.     printf("\nBye Byte\n");
  146. }
  147.  
  148.  
  149.  
  150. modem()
  151. {
  152.     char c;
  153.     FILE *fd;
  154.  
  155.     if ((fd = fopen(filename, "r")) != 0) {
  156.         while ((c = fgetc(fd)) != EOF) {
  157.             Cauxout(c);
  158.             if (c == '\n')
  159.                 Cauxout('\015');
  160.         }
  161.         fclose(fd);
  162.     }
  163. }
  164.  
  165.  
  166. list(file)
  167. char *file;
  168. {
  169.     char c;
  170.     FILE *fd;
  171.  
  172.     if ((fd = fopen(file, "r")) != 0) {
  173.         while ((c = fgetc(fd)) != EOF) {
  174.             putchar(c);
  175.         }
  176.         fclose(fd);
  177.     }
  178.     else
  179.         printf("%s does not exist\n", file);
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. hog()
  188. {
  189.     for (;;)
  190.         ;
  191. }
  192.  
  193.  
  194. print()
  195. {
  196.     char c;
  197.     FILE *fd;
  198.  
  199.     if ((fd = fopen(filename, "r")) != 0) {
  200.         while ((c = fgetc(fd)) != EOF) {
  201.             Cprnout(c);
  202.             if (c == '\n')
  203.                 Cprnout('\015');
  204.         }
  205.         fclose(fd);
  206.     }
  207. }
  208.  
  209.  
  210.  
  211. getline(buf, p)
  212. char *buf;
  213. char *p;
  214. {
  215.     Cconws(p);
  216.     buf[0] = 78;
  217.     Cconrs(buf);
  218.     buf[2+buf[1]] = '\0';
  219.     putchar('\n');
  220.     strcpy(buf, buf+2);
  221. }
  222. əəəəəəəəəə